package com.edu.web.user;

import com.edu.entity.blog.Article;
import com.edu.entity.chat.Chat;
import com.edu.entity.queryanswer.Query;
import com.edu.entity.shop.Video;
import com.edu.entity.user.EduUser;
import com.edu.entity.user.SysUser;
import com.edu.mapper.blog.ArticleMapper;
import com.edu.mapper.queryanswer.QueryMapper;
import com.edu.service.chat.EduChatService;
import com.edu.service.shop.VideoService;
import com.edu.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
public class ResisterController {
    @Autowired
    private UserService userService;
    @Autowired
    private QueryMapper queryMapper;
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private EduChatService eduChatService;
    @Autowired
    private VideoService videoService;
    @RequestMapping("/register")
    public String register(){
        return "register";
    }
    @RequestMapping("/relogin")
    public String relogin(){
        return "login";
    }

    @RequestMapping("/addUser")
    public String addUser(EduUser eduUser){
        System.out.println("sysuser11"+eduUser);
        Date date =new Date();
        eduUser.setCreatetime(date);
        BCryptPasswordEncoder encoder =new BCryptPasswordEncoder();
        eduUser.setPassword(encoder.encode(eduUser.getPassword().trim()));
        userService.insertUser(eduUser);
        return "register";
    }

    @RequestMapping("/m")
    public String pagequery(Model model){
        List<Query> list=queryMapper.pageList();
        model.addAttribute("query1",list.get(0));
        model.addAttribute("query2",list.get(1));
        model.addAttribute("query3",list.get(2));
        model.addAttribute("query4",list.get(3));
        model.addAttribute("query5",list.get(4));
        model.addAttribute("query6",list.get(5));
        model.addAttribute("query7",list.get(6));
        model.addAttribute("query8",list.get(7));
        List<Article> articleList=articleMapper.pageList();
        model.addAttribute("blog1",articleList.get(0));
        model.addAttribute("blog2",articleList.get(1));
        model.addAttribute("blog3",articleList.get(2));
        model.addAttribute("blog4",articleList.get(3));
        model.addAttribute("blog5",articleList.get(4));
        model.addAttribute("blog6",articleList.get(5));
        model.addAttribute("blog7",articleList.get(6));
        model.addAttribute("blog8",articleList.get(7));
        List<Chat> chatList=eduChatService.pageList();
        model.addAttribute("chat1",chatList.get(0));
        model.addAttribute("chat2",chatList.get(1));
        model.addAttribute("chat3",chatList.get(2));
        model.addAttribute("chat4",chatList.get(3));
        model.addAttribute("chat5",chatList.get(4));
        model.addAttribute("chat6",chatList.get(5));
        model.addAttribute("chat7",chatList.get(6));
        List<Video> videoList=videoService.pageList();
        model.addAttribute("video1",videoList.get(0));
        model.addAttribute("video2",videoList.get(1));
        model.addAttribute("video3",videoList.get(2));
        model.addAttribute("video4",videoList.get(3));
        model.addAttribute("video5",videoList.get(4));
        model.addAttribute("video6",videoList.get(5));
        model.addAttribute("video7",videoList.get(6));
        model.addAttribute("video8",videoList.get(7));
        model.addAttribute("video9",videoList.get(8));
        model.addAttribute("video10",videoList.get(9));
        List<EduUser> eduUserList=userService.pageList();
        model.addAttribute("edu1",eduUserList.get(0));
        model.addAttribute("edu2",eduUserList.get(1));
        model.addAttribute("edu3",eduUserList.get(2));
        model.addAttribute("edu4",eduUserList.get(3));
        model.addAttribute("edu5",eduUserList.get(4));
        model.addAttribute("edu6",eduUserList.get(5));
        model.addAttribute("edu7",eduUserList.get(6));
        model.addAttribute("edu8",eduUserList.get(7));
        Video video=videoService.top(126);
        Video video1=videoService.top(127);
        model.addAttribute("videotop",video);
        model.addAttribute("videotop1",video1);
        System.out.println(video);
        return "index";
    }
}
